﻿Public Class ProductsForm

    Private Sub ProductsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProductsBindingNavigatorSaveItem.Click
        Me.Validate() 'elegxei tis times se epipedo formas

        Me.ProductsBindingSource.EndEdit()
        If Me.NorthwindDataSet.Products.HasErrors Then

            For Each product As NorthwindDataSet.ProductsRow In NorthwindDataSet.Products

                If product.RowError <> String.Empty Then
                    MessageBox.Show(product.ProductName & " :" & product.RowError)
                End If

            Next
            MessageBox.Show("Saving cannot occur")
        Else
            Me.TableAdapterManager.UpdateAll(Me.NorthwindDataSet)
            MessageBox.Show("ola kala")
        End If

        Me.TableAdapterManager.UpdateAll(Me.NorthwindDataSet) 'gia enimrwsi apo to dataset sti vasi dedomenwn

    End Sub

    Private Sub ProductsForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'NorthwindDataSet.Products' table. You can move, or remove it, as needed.
        Me.ProductsTableAdapter.Fill(Me.NorthwindDataSet.Products)
        If Control.IsKeyLocked(Keys.CapsLock) Then
            MessageBox.Show("The Caps Lock key is ON.")
        Else
            MsgBox("caps lock is off")
        End If
    End Sub

    Private Sub UnitPriceTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UnitPriceTextBox.TextChanged
      
    End Sub

    Private Sub UnitPriceTextBox_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UnitPriceTextBox.Leave
        ' tha mporouse na mpei k sto envent validating
        'tha emfanistei to minima se periptwsi pou o xristis fugei apo to textbox
        Dim i As Integer
        If Integer.TryParse(UnitPriceTextBox.Text, i) Then
            If i <= 0 Then
                MessageBox.Show("i timi den mporei na einai arnitiki")
                UnitPriceTextBox.Focus() 'den mporei na fugei o kersoras an den dwsei o xristis swsti timi
            End If
        Else
            'Convert.ToInt32(UnitPriceTextBox.Text) <= 0 Then 'elegxoume gia tin timi tou textbox
            MessageBox.Show("i timi prepei na einai arithmos")
            UnitPriceTextBox.Focus()

        End If
        If Control.IsKeyLocked(Keys.NumLock) Then
            MessageBox.Show("The Num Lock key is ON.")
        End If
    End Sub
End Class